home *** CD-ROM | disk | FTP | other *** search
- #include <QuickDraw.h>
- #include <MacTypes.h>
- #include <DialogMgr.h>
- #include <WindowMgr.h>
- #include <DialogMgr.h>
- #include <EventMgr.h>
- #include <MemoryMgr.h>
- #include <TextEdit.h>
- #include <StdFilePkg.h>
- #include <MenuMgr.h>
- #include <ListMgr.h>
- #include <FontMgr.h>
- #include <ToolBoxUtil.h>
- #include <ControlMgr.h>
- #include <ResourceMgr.h>
-
- typedef struct{
- ListHandle helpList;
- int helpDlogType;
- ControlHandle ScrollHdl;
- int scrollAmt;
- int scrollCode;
- int linesVis;
- TEHandle hTE;
- PicHandle helpPict;
- Rect pictRect;
- } DlogInfo, *DlogIPtr, **DlogIHdl;
-
- typedef struct {
- int topicsID;
- int infoID;
- int locateID;
- Point text1Loc;
- Point text2Loc;
- Point text3Loc;
- int topicFont;
- int topicSize;
- Rect topicRect;
- int textFont;
- int textSize;
- int titleFont;
- int titleSize;
- int titleFace;
- Rect titleRect;
- Rect textRect;
- } HelpTemplate, *HTPtr, **HTHdl;
-
- #define TEMPLATE 500
- #define HELPMENU 30001
- #define ScrlLine 10
- #define NIL 0L
- #define QuitHelp 0
- enum { HELPTOPICS,HELPWINDOW };
- enum { TOPICS=1,
- NEXT,
- PREVIOUS,
- HELPCANCEL };
- enum { PictNotFound=-606,
- HMgrNotFound,
- TopicsDlogErr,
- TextDlogErr,
- TextInsErr,
- RsrcFileErr,
- TemplateErr };
-
- static MenuHandle GLhelpMenu;
- static int helpResNum=-1;
- static Boolean needsClosing=TRUE;
-
- pascal Boolean helpFilter();
- pascal void HelpScrollProc();
-
-
- /***********************************************************
- Do help on an application
- 1. helpFileName - help file name or null string to
- look for help in CurResFile()
- 2. text1,text2,text3: 3 lines of text for topics
- dialog box
- 3. styleText: True to use text edit with style, else
- use old text edit (Style text requires System>4.0).
- 4. fileType: HMgr resource file SFFileType or 'ANYR'
- to look for any resource file
-
- ErrorCodes on return
- noErr(0): no errors
- PictNotFound(-606): Error accessing PICT resource
- HMgrNotFound(-605): Error accessing HMgr resource
- TopicsDlogErr(-604): could not create Help Topic dialog
- TextDlogErr(-603): could not create Help Text dialog
- TextInsErr(-602): could not insert Help text
- RsrcFileErr(-601): could not open resource file
- TemplateErr(-600): could not open Help Template
- ***********************************************************/
-
- DoHelp(helpFileName,text1,text2,text3,styleText,fileType)
- char *helpFileName,*text1,*text2,*text3;
- Boolean styleText;
- long fileType;
- {
- GrafPtr save_graf;
- int saveResNum,helpTopic,helpError;
-
- GetPort(&save_graf);
- saveResNum=CurResFile();
-
- if(helpResNum<0)
- { if((helpError=OpenHelp(helpFileName,fileType))<=0)
- { SetPort(save_graf);
- return(helpError);
- }
- }
- UseResFile(helpResNum);
-
- helpTopic=1;
- while ((helpTopic=GetHelpTopic(helpTopic,text1,
- text2,text3,GLhelpMenu))>QuitHelp)
- { if((helpTopic=ShowHelpTopic(helpTopic,styleText,
- GLhelpMenu))<=QuitHelp) break;
- }
-
- UseResFile(saveResNum);
- SetPort(save_graf);
- return(helpTopic);
- }
-
- /***********************************************************
- If want to free some memory or if want to get help
- using a different HMgr resource file, call this routine
- to dispose of the previously opened HMgr file info
- ***********************************************************/
-
- DisposeHelp()
- {
- if(needsClosing)
- CloseResFile(helpResNum);
- helpResNum=-1;
- needsClosing=TRUE;
- DisposeMenu(GLhelpMenu);
- }
-
- /***********************************************************
- Open the HMgr resource file or if helpFileName is
- empty use the HMgr resources in CurResFile()
- ***********************************************************/
-
- static OpenHelp(helpFileName,fileType)
- char *helpFileName;
- long fileType;
- {
- register int i;
- Point upleft;
- SFReply filetry;
- DialogPtr dptr;
- char volName[2];
- HTHdl HT;
-
- HT=(HTHdl)GetResource('HTpl',TEMPLATE);
- if(ResError()!=noErr)
- return(TemplateErr);
-
- if(helpFileName[0]==0)
- { helpResNum=CurResFile();
- needsClosing=FALSE;
- }
- else if((helpResNum=OpenResFile(helpFileName))<0)
- { upleft.v=85;
- upleft.h=82;
- volName[0]=0;
- ParamText(helpFileName,"\p","\p","\p");
- dptr=GetNewDialog((**HT).locateID,NIL,-1L);
- DrawDialog(dptr);
- if(fileType=='ANYR')
- SFGetFile(upleft,"\pHelp",NIL,-1,fileType,
- NIL,&filetry);
- else
- SFGetFile(upleft,"\pHelp",NIL,1,fileType,
- NIL,&filetry);
- DisposDialog(dptr);
- if(filetry.good)
- { SetVol(volName,filetry.vRefNum);
- if((helpResNum=OpenResFile(filetry.fName))<0)
- return(RsrcFileErr);
- }
- else
- return(QuitHelp);
- }
-
- GLhelpMenu=NewMenu(HELPMENU,"\pHelp");
- AddResMenu(GLhelpMenu,'HMgr');
-
- return(TRUE);
- }
-
- /***********************************************************
- DIsplay dialog box and select help topics
- text1, text2, and text3 are three lines of text to
- appear in the dialog box
- If topic selected return helpTopic, if help canceled
- return QuitHelp, if error occurs return error code
- ***********************************************************/
-
- static GetHelpTopic(helpTopic,text1,text2,text3,helpMenu)
- int helpTopic;
- char *text1,*text2,*text3;
- MenuHandle helpMenu;
- {
- DialogPtr dptr;
- int ditem;
- int numHelp=CountMItems(helpMenu);
- register int i;
- ListHandle helpList;
- DlogIHdl helpInfo;
- Point cSize;
- Cell theCell;
- char helpItem[80];
- Rect dataBounds,helpDestRect;
- HTHdl HT;
-
- HT=(HTHdl)GetResource('HTpl',TEMPLATE);
- if(ResError()!=noErr)
- return(TemplateErr);
-
- dptr=GetNewDialog((**HT).topicsID,NIL,-1L);
- SetPort(dptr);
- FrameDefaultButton(dptr);
-
- /* Draw three text strings */
- MoveTo((**HT).text1Loc.h,(**HT).text1Loc.v);
- DrawString(text1);
- MoveTo((**HT).text2Loc.h,(**HT).text2Loc.v);
- DrawString(text2);
- MoveTo((**HT).text3Loc.h,(**HT).text3Loc.v);
- DrawString(text3);
-
- TextFont((**HT).topicFont);
- TextSize((**HT).topicSize);
- TextFace(0);
- SetRect(&helpDestRect,(**HT).topicRect.left,
- (**HT).topicRect.top,(**HT).topicRect.right,
- (**HT).topicRect.bottom);
- FrameRect(&helpDestRect);
-
- /* Initilize new list manger record */
- InsetRect(&helpDestRect,1,1);
- helpDestRect.right-=14;
- SetRect(&dataBounds,0,0,1,numHelp);
- cSize.h=cSize.v=0;
- helpList=LNew(&helpDestRect,&dataBounds,cSize,0,
- (WindowPtr)dptr,TRUE,FALSE,FALSE,TRUE);
- if(helpList==NIL)
- { DisposDialog(dptr);
- return(TopicsDlogErr);
- }
-
- /* Initialise dialog info record */
- helpInfo=(DlogIHdl)NewHandle((Size)sizeof(DlogInfo));
- if(helpInfo==NIL)
- { LDispose(helpList);
- DisposDialog(dptr);
- return(TopicsDlogErr);
- }
- SetWRefCon(dptr,(long)helpInfo);
- (**helpInfo).helpList=helpList;
- (**helpInfo).helpDlogType=HELPTOPICS;
-
- /* Fill the list */
- theCell.h=0;
- for(i=1;i<=numHelp;i++)
- { GetItem(helpMenu,i,helpItem);
- theCell.v=i-1;
- LSetCell(&helpItem[1],(int)helpItem[0],
- theCell,helpList);
- }
- (**helpList).selFlags=lOnlyOne;
- theCell.v=helpTopic-1;
- LSetSelect(TRUE,theCell,helpList);
- LAutoScroll(helpList);
-
- do
- { ModalDialog(&helpFilter,&ditem);
- if(ditem==OK)
- { theCell.h=theCell.v=0;
- LGetSelect(TRUE,&theCell,helpList);
- helpTopic=theCell.v+1;
- }
- } while (ditem>Cancel);
-
- DisposHandle(helpInfo);
- LDispose(helpList);
- DisposDialog(dptr);
- if(ditem==OK)
- return(helpTopic);
- else
- return(QuitHelp);
- }
-
- /***********************************************************
- Filter Help dialog events
- On mouseDown: call LClick in HELPTOPICS dialogs
- call HelpDoScroll in HELPWINDOW dialogs
- On keyDown: check for return or enter
- ***********************************************************/
-
- pascal Boolean helpFilter(dptr,eventp,itemHit)
- DialogPtr dptr;
- EventRecord *eventp;
- int *itemHit;
- {
- char theChar;
- Point where;
- DlogIHdl helpInfo=(DlogIHdl)GetWRefCon(dptr);
-
- switch(eventp->what)
- { case mouseDown:
- if((**helpInfo).helpDlogType==HELPTOPICS)
- { where=eventp->where;
- GlobalToLocal(&where);
- if(LClick(where,eventp->modifiers,
- (**helpInfo).helpList))
- { *itemHit=1;
- return(TRUE);
- }
- }
- else
- { if(HelpDoScroll(dptr,eventp->where,
- helpInfo))
- { *itemHit=11;
- return(TRUE);
- }
- }
- break;
- case autoKey:
- case keyDown:
- theChar=eventp->message&charCodeMask;
- if(theChar==13||theChar==3)
- { *itemHit=1;
- return(TRUE);
- }
- break;
- default:
- break;
- }
- return(FALSE);
- }
-
- /***********************************************************
- Show the help topic number helpTopic
- if Topics selected return helptopic, if help canceled
- return QuitHelp, if error occurs return error code
- ***********************************************************/
-
- static ShowHelpTopic(helpTopic,styleText,helpMenu)
- int helpTopic;
- Boolean styleText;
- MenuHandle helpMenu;
- {
- char resName[80],cTitle[5];
- int ditem,helpError;
- int numHelp=CountMItems(helpMenu);
- DialogPtr dptr;
- DlogIHdl helpInfo;
- ControlHandle ScrollHdl;
- Rect helpDestRect,scrollRect;
- Boolean textWindow;
- TEHandle helphTE;
- HTHdl HT=(HTHdl)GetResource('HTpl',TEMPLATE);
-
- dptr=GetNewDialog((**HT).infoID,NIL,-1L);
- SetPort(dptr);
- FrameDefaultButton(dptr);
- GetShowTitle(resName,helpTopic,helpMenu);
-
- SetRect(&helpDestRect,(**HT).textRect.left,
- (**HT).textRect.top,(**HT).textRect.right,
- (**HT).textRect.bottom);
- FrameRect(&helpDestRect);
-
- /* Set up scroll bar and text destRect */
- SetRect(&scrollRect,helpDestRect.right-16,
- helpDestRect.top,helpDestRect.right,
- helpDestRect.bottom);
- InsetRect(&helpDestRect,1,1);
- helpDestRect.left+=4;
- helpDestRect.right=scrollRect.left-4;
- cTitle[0]=0;
- ScrollHdl=NewControl(dptr,&scrollRect,
- cTitle,1,0,0,0,scrollBarProc,0);
- Draw1Control(ScrollHdl);
-
- /* Initialize Text Edit record */
- if(styleText)
- helphTE=TEStylNew(&helpDestRect,&helpDestRect);
- else
- helphTE=TENew(&helpDestRect,&helpDestRect);
- if((helphTE==NIL)||(ScrollHdl==NIL))
- { DisposDialog(dptr);
- return(TextDlogErr);
- }
-
- /* Initalize Dialog info record */
- helpInfo=(DlogIHdl)NewHandle((Size)sizeof(DlogInfo));
- if(helpInfo==NIL)
- { TEDispose(helphTE);
- DisposDialog(dptr);
- return(TextDlogErr);
- }
- SetWRefCon(dptr,(long)helpInfo);
- (**helpInfo).helpDlogType=HELPWINDOW;
- (**helpInfo).ScrollHdl=ScrollHdl;
- (**helpInfo).linesVis=(helpDestRect.bottom-
- helpDestRect.top)/ScrlLine;
- (**helpInfo).hTE=helphTE;
- (**helpInfo).helpPict=NIL;
-
- if(helpError=InsertHelpText(resName,styleText,
- helpInfo,helphTE))
- { DisposHandle(helpInfo);
- TEDispose(helphTE);
- DisposDialog(dptr);
- return(helpError);
- }
-
- do
- { ModalDialog(&helpFilter,&ditem);
- if((ditem==NEXT)||(ditem==PREVIOUS))
- { if(ditem==NEXT) helpTopic++;
- if(ditem==PREVIOUS) helpTopic--;
- if(helpTopic>numHelp) helpTopic=1;
- if(helpTopic<1) helpTopic=numHelp;
- GetShowTitle(resName,helpTopic,helpMenu);
- ClearPict(helpInfo);
- if(helpError=InsertHelpText(resName,styleText,
- helpInfo,helphTE))
- { helpTopic=helpError;
- ditem=TOPICS;
- }
- }
- } while ((ditem!=TOPICS)&&(ditem!=HELPCANCEL));
-
- ClearPict(helpInfo);
- DisposHandle(helpInfo);
- TEDispose(helphTE);
- DisposDialog(dptr);
- if(ditem==TOPICS)
- return(helpTopic);
- else
- return(QuitHelp);
- }
-
- /***********************************************************
- Get and show help title - if title is too long, attempt
- is made to stop before first dash in help title
- ***********************************************************/
-
- static GetShowTitle(resName,helpTopic,helpMenu)
- char *resName;
- int helpTopic;
- MenuHandle helpMenu;
- {
- GrafPtr curPort;
- char showName[80];
- register int i,dashLoc=0;
- Rect titleRect;
- HTHdl HT=(HTHdl)GetResource('HTpl',TEMPLATE);
-
- SetRect(&titleRect,(**HT).titleRect.left,
- (**HT).titleRect.top,(**HT).titleRect.right,
- (**HT).titleRect.bottom);
- GetItem(helpMenu,helpTopic,resName);
- showName[0]=resName[0];
- for(i=1;i<=resName[0];i++)
- { showName[i]=resName[i];
- if((dashLoc==0)&&(showName[i]=='-'))
- dashLoc=i;
- }
- TextFont((**HT).titleFont);
- TextSize((**HT).titleSize);
- TextFace((**HT).titleFace);
- if(StringWidth(showName)>
- (titleRect.right-titleRect.left))
- { if(dashLoc!=0)
- showName[0]=dashLoc-1;
- }
-
- EraseRect(&titleRect);
- ClipRect(&titleRect);
- MoveTo(titleRect.left,titleRect.top+(**HT).titleSize);
- DrawString(showName);
- GetPort(&curPort);
- ClipRect(&curPort->portRect);
- TextFont((**HT).textFont);
- TextSize((**HT).textSize);
- TextFace(0);
- }
-
- /***********************************************************
- Load text in named HMgr resource (resName) into the
- text edit record. Format of HMgr resource given in
- documentation. If load sucessful return FALSE. If
- error occurs return error code.
- ***********************************************************/
-
- static InsertHelpText(resName,styleText,helpInfo,helphTE)
- char *resName;
- Boolean styleText;
- DlogIHdl helpInfo;
- TEHandle helphTE;
- {
- Handle resHdl,newText;
- TEStyleHandle stHdl,newstHdl;
- STHandle stabHdl,newstabHdl;
- LHHandle lhTab;
- NullStHandle nullStyle;
- TextStyle newStyle;
- long *lptr;
- char *rptr;
- int curValue,lineHeight,totalLines;
- int totalHeight,horiz,vert,lm,pictID;
- int *picSize;
- Rect *rectPtr;
- PicHandle helpPict;
- Rect dest;
- Size hSize;
- HTHdl HT=(HTHdl)GetResource('HTpl',TEMPLATE);
-
- resHdl=GetNamedResource('HMgr',resName);
- if(ResError()!=noErr)
- return(HMgrNotFound);
- if(SizeResource(resHdl)==2) /* If true load in PICT */
- return(InsertHelpPict(resHdl,helpInfo,helphTE));
-
- if(styleText)
- { stHdl=GetStylHandle(helphTE);
- stabHdl=(**stHdl).styleTab;
- lhTab=(**stHdl).lhTab;
- nullStyle=(**stHdl).nullStyle;
- }
-
- /* Get the style table */
- HLock(resHdl);
- rptr=(char *)(*resHdl);
- lptr=(long *)rptr;
- rptr+=(int)sizeof(long);
- if(styleText)
- { newstHdl=(TEStyleHandle)
- NewHandle(hSize=(Size)(*lptr));
- if(MemError()!=noErr)
- { HUnlock(resHdl);
- ReleaseResource(resHdl);
- return(TextInsErr);
- }
- HLock(newstHdl);
- BlockMove(rptr,(char *)(*newstHdl),hSize);
- HUnlock(newstHdl);
- (**newstHdl).lhTab=lhTab;
- (**newstHdl).nullStyle=nullStyle;
- }
- rptr+=(int)(*lptr);
-
- /* Get style runs */
- lptr=(long *)rptr;
- rptr+=(int)sizeof(long);
- if(styleText)
- { newstabHdl=(STHandle)NewHandle(hSize=(Size)(*lptr));
- if(MemError()!=noErr)
- { HUnlock(resHdl);
- ReleaseResource(resHdl);
- DisposHandle(newstHdl);
- return(TextInsErr);
- }
- HLock(newstabHdl);
- BlockMove(rptr,(char *)(*newstabHdl),hSize);
- HUnlock(newstabHdl);
- (**newstHdl).styleTab=newstabHdl;
- }
- rptr+=(int)(*lptr);
-
- /* Get the text */
- lptr=(long *)rptr;
- rptr+=(int)sizeof(long);
- newText=NewHandle(hSize=(Size)(*lptr));
- if(MemError()!=noErr)
- { HUnlock(resHdl);
- ReleaseResource(resHdl);
- if(styleText)
- { DisposHandle(newstHdl);
- DisposHandle(newstabHdl);
- }
- return(TextInsErr);
- }
- HLock(newText);
- BlockMove(rptr,(char *)(*newText),hSize);
- HUnlock(newText);
- HUnlock(resHdl);
- ReleaseResource(resHdl);
-
- EraseRect(&(**helphTE).viewRect);
- DisposHandle((**helphTE).hText);
- (**helphTE).hText=newText;
- if(styleText)
- { SetStylHandle(newstHdl,helphTE);
- DisposHandle(stabHdl);
- }
-
- TECalText(helphTE);
- (**helphTE).destRect=(**helphTE).viewRect;
- SetCtlValue((**helpInfo).ScrollHdl,0);
-
- /* Find total lines and set scroll bar maximm */
- if((lineHeight=(**helphTE).lineHeight)<0)
- { totalHeight=TEGetHeight((long)(**helphTE).nLines,
- (long)1,helphTE);
- totalLines=totalHeight/ScrlLine+1;
- }
- else
- { if(lineHeight==ScrlLine)
- totalLines=(**helphTE).nLines;
- else
- { totalHeight=(**helphTE).nLines*lineHeight;
- totalLines=totalHeight/ScrlLine+1;
- }
- }
- if(totalLines>(**helpInfo).linesVis)
- SetCtlMax((**helpInfo).ScrollHdl,
- totalLines-(**helpInfo).linesVis);
- else
- SetCtlMax((**helpInfo).ScrollHdl,0);
- TEUpdate(&(**helphTE).viewRect,helphTE);
-
- return(FALSE);
- }
-
- /******************************************************************
- This help info is in the form of a PICT
- ******************************************************************/
-
- static InsertHelpPict(resHdl,helpInfo,helphTE)
- Handle resHdl;
- DlogIHdl helpInfo;
- TEHandle helphTE;
- {
- int pictID,horiz,vert,tm,lm,totalLines;
- Rect *rectPtr,pictRect;
- PicHandle helpPict;
- GrafPtr curPort;
-
- pictID=*((int *)(*resHdl));
- ReleaseResource(resHdl);
- helpPict=GetPicture(pictID);
- if(helpPict==NIL)
- return(PictNotFound);
-
- HLock(helpPict);
- rectPtr=(Rect *)((int *)*helpPict+1);
- horiz=rectPtr->right-rectPtr->left;
- lm=((**helphTE).viewRect.right-(**helphTE).viewRect.left-horiz)/2;
- if(lm<0) lm=0;
- lm+=(**helphTE).viewRect.left;
- vert=rectPtr->bottom-rectPtr->top;
- tm=(**helphTE).viewRect.top+1;
- SetRect(&pictRect,lm,tm,lm+horiz,tm+vert);
- HUnlock(helpPict);
- EraseRect(&(**helphTE).viewRect);
- ClipRect(&(**helphTE).viewRect);
- DrawPicture(helpPict,&pictRect);
- GetPort(&curPort);
- ClipRect(&curPort->portRect);
-
- (**helpInfo).helpPict=helpPict;
- (**helpInfo).pictRect=pictRect;
- SetCtlValue((**helpInfo).ScrollHdl,0);
- totalLines=vert/ScrlLine+1;
- if(totalLines>(**helpInfo).linesVis)
- SetCtlMax((**helpInfo).ScrollHdl,
- totalLines-(**helpInfo).linesVis);
- else
- SetCtlMax((**helpInfo).ScrollHdl,0);
-
- return(FALSE);
- }
-
- /***********************************************************
- Release PICT resource if one is being used
- ***********************************************************/
-
- static ClearPict(helpInfo)
- DlogIHdl helpInfo;
- {
- if((**helpInfo).helpPict!=NIL)
- { ReleaseResource((**helpInfo).helpPict);
- (**helpInfo).helpPict=NIL;
- }
- }
-
- /***********************************************************
- Frame the default dialog box button
- ***********************************************************/
-
- static FrameDefaultButton(dptr)
- DialogPtr dptr;
- {
- Rect OKrect;
- int itype;
- Handle ihdl;
-
- PenSize(3,3);
- GetDItem(dptr,OK,&itype,&ihdl,&OKrect);
- InsetRect(&OKrect,-4,-4);
- FrameRoundRect(&OKrect,16,16);
- PenSize(1,1);
- }
-
- /***********************************************************
- Do scrolling, return TRUE if scrolled or FALSE if not
- ***********************************************************/
-
- static HelpDoScroll(theWindow,where,helpInfo)
- WindowPtr theWindow;
- long where;
- DlogIHdl helpInfo;
- {
- int partCode,oldValue,newValue,units;
- ControlHandle control;
-
- GlobalToLocal(&where);
- partCode=FindControl(where,theWindow,&control);
- if(partCode==0) return(FALSE);
- if(control!=(**helpInfo).ScrollHdl) return(FALSE);
-
- switch(partCode)
- { case inUpButton:
- case inDownButton:
- case inPageUp:
- case inPageDown:
- switch(partCode)
- { case inUpButton:
- (**helpInfo).scrollAmt=-1;
- break;
- case inDownButton:
- (**helpInfo).scrollAmt=1;
- break;
- case inPageUp:
- (**helpInfo).scrollAmt=
- -(**helpInfo).linesVis;
- break;
- case inPageDown:
- (**helpInfo).scrollAmt=
- (**helpInfo).linesVis;
- break;
- }
- (**helpInfo).scrollCode=partCode;
- TrackControl(control,where,&HelpScrollProc);
- break;
- case inThumb:
- oldValue=GetCtlValue(control);
- if(TrackControl(control,where,-1L))
- { newValue=GetCtlValue(control);
- if(units=oldValue-newValue)
- HelpScroll(units,helpInfo);
- }
- break;
- default:
- break;
- }
- return(TRUE);
- }
-
- /***********************************************************
- Action procedure for scrolling
- ***********************************************************/
-
- pascal void HelpScrollProc(control,theCode)
- ControlHandle control;
- int theCode;
- {
- int max,oldValue,newValue,units;
- WindowPtr ctrlWindow=(*control)->contrlOwner;
- DlogIHdl helpInfo=(DlogIHdl)GetWRefCon(ctrlWindow);
-
- if(theCode==(**helpInfo).scrollCode)
- { oldValue=GetCtlValue(control);
- newValue=oldValue+(**helpInfo).scrollAmt;
- if(newValue<0) newValue=0;
- max=GetCtlMax(control);
- if(newValue>max) newValue=max;
- SetCtlValue(control,newValue);
- if(units=oldValue-newValue)
- HelpScroll(units,helpInfo);
- }
- }
-
- /***********************************************************
- Scroll the help window by units lines
- ***********************************************************/
-
- static HelpScroll(units,helpInfo)
- int units;
- DlogIHdl helpInfo;
- {
- RgnHandle tmpRgn;
- GrafPtr curPort;
- Rect pictRect,viewRect;
- int tm,absunits=units<0 ? -units : units;
-
- if((**helpInfo).helpPict==NIL)
- TEScroll(0,ScrlLine*units,(**helpInfo).hTE);
- else
- { viewRect=(**((**helpInfo).hTE)).viewRect;
- if(absunits>(**helpInfo).linesVis)
- InvalRect(&viewRect);
- else
- { tmpRgn=NewRgn();
- ScrollRect(&viewRect,0,ScrlLine*units,tmpRgn);
- InvalRgn(tmpRgn);
- DisposeRgn(tmpRgn);
- }
- GetPort(&curPort);
- BeginUpdate(curPort);
- ClipRect(&viewRect);
- EraseRect(&viewRect);
- tm=GetCtlValue((**helpInfo).ScrollHdl)*ScrlLine;
- pictRect=(**helpInfo).pictRect;
- OffsetRect(&pictRect,0,-tm);
- DrawPicture((**helpInfo).helpPict,&pictRect);
- ClipRect(&curPort->portRect);
- EndUpdate(curPort);
- }
- }
-